<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="ID" prop="tUserId">
        <el-input
          v-model="queryParams.tUserId"
          placeholder="ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户昵称" prop="userNick">
        <el-input
          v-model="queryParams.userNick"
          placeholder="请输入用户昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务上下文信息" prop="operationDescription">
        <el-input
          v-model="queryParams.operationDescription"
          placeholder="请输入业务上下文信息比如业务id，任务名称什么的，系统内部划转记录。"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="乐观锁版本号" prop="version">
        <el-input
          v-model="queryParams.version"
          placeholder="请输入乐观锁版本号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="语言类型编码" prop="langCode">
        <el-input
          v-model="queryParams.langCode"
          placeholder="语言类型编码(如有必要)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会员id" prop="vipId">
        <el-input
          v-model="queryParams.vipId"
          placeholder="请输入会员id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="扩展字段1" prop="extendA">
        <el-input
          v-model="queryParams.extendA"
          placeholder="请输入扩展字段1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="扩展字段2" prop="extendB">
        <el-input
          v-model="queryParams.extendB"
          placeholder="请输入扩展字段2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="扩展字段3" prop="extendC">
        <el-input
          v-model="queryParams.extendC"
          placeholder="请输入扩展字段3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代理ID" prop="agentId">
        <el-input
          v-model="queryParams.agentId"
          placeholder="请输入代理ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="order_id/issue_id" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入支付需要的order_id或下发issue_id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="金额" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="充值回调url" prop="url">
        <el-input
          v-model="queryParams.url"
          placeholder="请输入充值回调url"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付时间戳记录" prop="time">
        <el-date-picker clearable
          v-model="queryParams.time"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择支付时间戳记录">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="签名信息完整记录" prop="sign">
        <el-input
          v-model="queryParams.sign"
          placeholder="请输入签名信息完整记录"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收款地址" prop="addressUser">
        <el-input
          v-model="queryParams.addressUser"
          placeholder="请输入提现时用户的收款地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="ID字符串" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="ID字符串"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:history:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:history:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:history:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:history:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="historyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="id" />
      <el-table-column label="用户ID" align="center" prop="tUserId" />
      <el-table-column label="用户昵称" align="center" prop="userNick" />
      <el-table-column label="操作类型" align="center" prop="operationType" />

      <el-table-column label="业务上下文信息" align="center" prop="operationDescription" />
      <el-table-column label="金额" align="center" prop="amount" />
      <el-table-column label="order_id/issue_id" align="center" prop="orderId" />
      <el-table-column label="操作状态" align="center" prop="operationStatus" />
<!--      <el-table-column label="乐观锁版本号" align="center" prop="version" />-->
<!--      <el-table-column label="语言类型编码" align="center" prop="langCode" />-->
<!--      <el-table-column label="会员id" align="center" prop="vipId" />-->
      <el-table-column label="扩展字段1" align="center" prop="extendA" />
      <el-table-column label="扩展字段2" align="center" prop="extendB" />
      <el-table-column label="扩展字段3" align="center" prop="extendC" />
      <el-table-column label="代理ID" align="center" prop="agentId" />


      <el-table-column label="充值回调地址" align="center" prop="url" />
      <el-table-column label="支付时间戳" align="center" prop="time" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.time, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="签名信息" align="center" prop="sign" />
      <el-table-column label="收款地址" align="center" prop="addressUser" />
      <el-table-column label="ID字符串" align="center" prop="userId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:history:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:history:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改支付记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="ID" prop="tUserId">
          <el-input v-model="form.tUserId" placeholder="请输入关联前端用户表ID" />
        </el-form-item>
        <el-form-item label="用户昵称" prop="userNick">
          <el-input v-model="form.userNick" placeholder="请输入用户昵称" />
        </el-form-item>
        <el-form-item label="业务上下文信息比如业务id，任务名称什么的，系统内部划转记录。" prop="operationDescription">
          <el-input v-model="form.operationDescription" placeholder="请输入业务上下文信息" />
        </el-form-item>
        <el-form-item label="乐观锁版本号" prop="version">
          <el-input v-model="form.version" placeholder="请输入乐观锁版本号" />
        </el-form-item>
        <el-form-item label="当前账户语言类型编码(如有必要)" prop="langCode">
          <el-input v-model="form.langCode" placeholder="请输入当前账户语言类型编码(如有必要)" />
        </el-form-item>
        <el-form-item label="会员id" prop="vipId">
          <el-input v-model="form.vipId" placeholder="请输入会员id" />
        </el-form-item>
        <el-form-item label="扩展字段1" prop="extendA">
          <el-input v-model="form.extendA" placeholder="请输入扩展字段1" />
        </el-form-item>
        <el-form-item label="扩展字段2" prop="extendB">
          <el-input v-model="form.extendB" placeholder="请输入扩展字段2" />
        </el-form-item>
        <el-form-item label="扩展字段3" prop="extendC">
          <el-input v-model="form.extendC" placeholder="请输入扩展字段3" />
        </el-form-item>
        <el-form-item label="代理ID" prop="agentId">
          <el-input v-model="form.agentId" placeholder="请输入代理ID" />
        </el-form-item>
        <el-form-item label="支付需要的order_id或下发issue_id" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入支付需要的order_id或下发issue_id" />
        </el-form-item>
        <el-form-item label="金额" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入金额" />
        </el-form-item>
        <el-form-item label="充值回调url" prop="url">
          <el-input v-model="form.url" placeholder="请输入充值回调url" />
        </el-form-item>
        <el-form-item label="支付时间戳记录" prop="time">
          <el-date-picker clearable
            v-model="form.time"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择支付时间戳记录">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="签名信息完整记录" prop="sign">
          <el-input v-model="form.sign" placeholder="请输入签名信息完整记录" />
        </el-form-item>
        <el-form-item label="提现时用户的收款地址" prop="addressUser">
          <el-input v-model="form.addressUser" placeholder="请输入提现时用户的收款地址" />
        </el-form-item>
        <el-form-item label="用户ID字符串" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID字符串" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listHistory, getHistory, delHistory, addHistory, updateHistory } from "@/api/system/history";

export default {
  name: "History",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 支付记录表格数据
      historyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tUserId: null,
        userNick: null,
        operationType: null,
        operationStatus: null,
        operationDescription: null,
        version: null,
        langCode: null,
        vipId: null,
        extendA: null,
        extendB: null,
        extendC: null,
        agentId: null,
        orderId: null,
        amount: null,
        url: null,
        time: null,
        sign: null,
        addressUser: null,
        userId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询支付记录列表 */
    getList() {
      this.loading = true;
      listHistory(this.queryParams).then(response => {
        this.historyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        tUserId: null,
        userNick: null,
        operationType: null,
        operationStatus: null,
        operationDescription: null,
        version: null,
        createTime: null,
        updateTime: null,
        updateBy: null,
        langCode: null,
        vipId: null,
        extendA: null,
        extendB: null,
        extendC: null,
        agentId: null,
        orderId: null,
        amount: null,
        url: null,
        time: null,
        sign: null,
        addressUser: null,
        userId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加支付记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getHistory(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改支付记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateHistory(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHistory(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除支付记录编号为"' + ids + '"的数据项？').then(function() {
        return delHistory(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/history/export', {
        ...this.queryParams
      }, `history_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
